/*********************************************************************
	Rhapsody	: 8.0
	Login		: Andrzej
	Component	: DefaultComponent
	Configuration 	: DefaultConfig
	Model Element	: AC
//!	Generated Date	: Sat, 15, Dec 2012 
	File Path	: DefaultComponent/DefaultConfig/Default/AC.java
*********************************************************************/

package Default;

//## auto_generated
import com.ibm.rational.rhapsody.oxf.*;
//## auto_generated
import com.ibm.rational.rhapsody.oxf.states.*;

//----------------------------------------------------------------------------
// Default/AC.java                                                                  
//----------------------------------------------------------------------------

//## package Default 


//## class AC 
public class AC implements RiJStateConcept {
    
    public Reactive reactive;		//## ignore 
    
    protected boolean isBroken = false;		//## attribute isBroken 
    
    protected boolean shouldWork = false;		//## attribute shouldWork 
    
    protected DecisionMaker parent;		//## link parent 
    
    //#[ ignore 
    public static final int RiJNonState=0;
    public static final int WorkStart=1;
    public static final int state_6=2;
    public static final int Work=3;
    public static final int terminationstate_4=4;
    public static final int Await=5;
    public static final int state_5=6;
    public static final int SetEnv=7;
    public static final int AwaitStartStopSignal=8;
    public static final int sendaction_2=9;
    //#]
    protected int rootState_subState;		//## ignore 
    
    protected int rootState_active;		//## ignore 
    
    protected int state_6_subState;		//## ignore 
    
    protected int state_6_active;		//## ignore 
    
    public static final int AC_Timeout_Work_id = 1;		//## ignore 
    
    public static final int AC_Timeout_Await_id = 2;		//## ignore 
    
    protected int state_5_subState;		//## ignore 
    
    protected int state_5_active;		//## ignore 
    
    public static final int AC_Timeout_SetEnv_id = 3;		//## ignore 
    
    
    //## statechart_method 
    public RiJThread getThread() {
        return reactive.getThread();
    }
    
    //## statechart_method 
    public void schedTimeout(long delay, long tmID, RiJStateReactive reactive) {
        getThread().schedTimeout(delay, tmID, reactive);
    }
    
    //## statechart_method 
    public void unschedTimeout(long tmID, RiJStateReactive reactive) {
        getThread().unschedTimeout(tmID, reactive);
    }
    
    //## statechart_method 
    public boolean isIn(int state) {
        return reactive.isIn(state);
    }
    
    //## statechart_method 
    public boolean isCompleted(int state) {
        return reactive.isCompleted(state);
    }
    
    //## statechart_method 
    public RiJEventConsumer getEventConsumer() {
        return (RiJEventConsumer)reactive;
    }
    
    //## statechart_method 
    public void gen(RiJEvent event) {
        reactive._gen(event);
    }
    
    //## statechart_method 
    public void queueEvent(RiJEvent event) {
        reactive.queueEvent(event);
    }
    
    //## statechart_method 
    public int takeEvent(RiJEvent event) {
        return reactive.takeEvent(event);
    }
    
    // Constructors
    
    //## auto_generated 
    public  AC(RiJThread p_thread) {
        reactive = new Reactive(p_thread);
    }
    
    //## auto_generated 
    public boolean getIsBroken() {
        return isBroken;
    }
    
    //## auto_generated 
    public void setIsBroken(boolean p_isBroken) {
        isBroken = p_isBroken;
    }
    
    //## auto_generated 
    public boolean getShouldWork() {
        return shouldWork;
    }
    
    //## auto_generated 
    public void setShouldWork(boolean p_shouldWork) {
        shouldWork = p_shouldWork;
    }
    
    //## auto_generated 
    public DecisionMaker getParent() {
        return parent;
    }
    
    //## auto_generated 
    public void __setParent(DecisionMaker p_DecisionMaker) {
        parent = p_DecisionMaker;
    }
    
    //## auto_generated 
    public void _setParent(DecisionMaker p_DecisionMaker) {
        if(parent != null)
            {
                parent.__setItsAC(null);
            }
        __setParent(p_DecisionMaker);
    }
    
    //## auto_generated 
    public void setParent(DecisionMaker p_DecisionMaker) {
        if(p_DecisionMaker != null)
            {
                p_DecisionMaker._setItsAC(this);
            }
        _setParent(p_DecisionMaker);
    }
    
    //## auto_generated 
    public void _clearParent() {
        parent = null;
    }
    
    //## auto_generated 
    public boolean startBehavior() {
        boolean done = false;
        done = reactive.startBehavior();
        return done;
    }
    
    //## ignore 
    public class Reactive extends RiJStateReactive {
        
        // Default constructor 
        public Reactive() {
            this(RiJMainThread.instance());
        }
        
        
        // Constructors
        
        public  Reactive(RiJThread p_thread) {
            super(p_thread);
            initStatechart();
        }
        
        //## statechart_method 
        public boolean isIn(int state) {
            if(state_5 == state)
                {
                    return isIn(WorkStart);
                }
            if(state_5_subState == state)
                {
                    return true;
                }
            if(state_6 == state)
                {
                    return isIn(WorkStart);
                }
            if(state_6_subState == state)
                {
                    return true;
                }
            if(rootState_subState == state)
                {
                    return true;
                }
            return false;
        }
        
        //## statechart_method 
        public boolean isCompleted(int state) {
            if(state_6 == state)
                {
                    return ( isIn(terminationstate_4) );
                }
            if(WorkStart == state)
                {
                    if(isCompleted(state_6) == false)
                        {
                            return false;
                        }
                    return true;
                }
            return true;
        }
        
        //## statechart_method 
        public void rootState_entDef() {
            {
                rootState_enter();
                rootStateEntDef();
            }
        }
        
        //## statechart_method 
        public int rootState_dispatchEvent(short id) {
            int res = RiJStateReactive.TAKE_EVENT_NOT_CONSUMED;
            switch (rootState_active) {
                case WorkStart:
                {
                    res = WorkStart_dispatchEvent(id);
                }
                break;
                case sendaction_2:
                {
                    res = sendaction_2_takeEvent(id);
                }
                break;
                default:
                    break;
            }
            return res;
        }
        
        //## statechart_method 
        public int WorkStart_dispatchEvent(short id) {
            int res = RiJStateReactive.TAKE_EVENT_NOT_CONSUMED;
            if(state_5_dispatchEvent(id) >= 0)
                {
                    res = RiJStateReactive.TAKE_EVENT_COMPLETE;
                    if(!isIn(WorkStart))
                        {
                            return res;
                        }
                }
            if(state_6_dispatchEvent(id) >= 0)
                {
                    res = RiJStateReactive.TAKE_EVENT_COMPLETE;
                    if(!isIn(WorkStart))
                        {
                            return res;
                        }
                }
            if(res == RiJStateReactive.TAKE_EVENT_NOT_CONSUMED)
                {
                    res = WorkStart_takeEvent(id);
                }
            return res;
        }
        
        //## statechart_method 
        public int state_6_dispatchEvent(short id) {
            int res = RiJStateReactive.TAKE_EVENT_NOT_CONSUMED;
            switch (state_6_active) {
                case Work:
                {
                    res = Work_takeEvent(id);
                }
                break;
                case terminationstate_4:
                {
                    res = terminationstate_4_takeEvent(id);
                }
                break;
                case Await:
                {
                    res = Await_takeEvent(id);
                }
                break;
                default:
                    break;
            }
            return res;
        }
        
        //## statechart_method 
        public int state_5_dispatchEvent(short id) {
            int res = RiJStateReactive.TAKE_EVENT_NOT_CONSUMED;
            switch (state_5_active) {
                case AwaitStartStopSignal:
                {
                    res = AwaitStartStopSignal_takeEvent(id);
                }
                break;
                case SetEnv:
                {
                    res = SetEnv_takeEvent(id);
                }
                break;
                default:
                    break;
            }
            return res;
        }
        
        //## auto_generated 
        protected void initStatechart() {
            rootState_subState = RiJNonState;
            rootState_active = RiJNonState;
            state_6_subState = RiJNonState;
            state_6_active = RiJNonState;
            state_5_subState = RiJNonState;
            state_5_active = RiJNonState;
        }
        
        //## statechart_method 
        public void sendaction_2Exit() {
        }
        
        //## statechart_method 
        public void AwaitStartStopSignalExit() {
        }
        
        //## statechart_method 
        public void Work_entDef() {
            Work_enter();
        }
        
        //## statechart_method 
        public void WorkStartEnter() {
        }
        
        //## statechart_method 
        public void WorkStart_entDef() {
            WorkStart_enter();
            state_5_entDef();
            state_6_entDef();
        }
        
        //## statechart_method 
        public void sendaction_2_exit() {
            sendaction_2Exit();
        }
        
        //## statechart_method 
        public void state_5EntDef() {
            AwaitStartStopSignal_entDef();
        }
        
        //## statechart_method 
        public void state_6_entDef() {
            state_6_enter();
            state_6EntDef();
        }
        
        //## statechart_method 
        public int sendaction_2_takeEvent(short id) {
            int res = RiJStateReactive.TAKE_EVENT_NOT_CONSUMED;
            if(event.isTypeOf(ACSYNACK.ACSYNACK_Default_id))
                {
                    res = sendaction_2TakeACSYNACK();
                }
            
            return res;
        }
        
        //## statechart_method 
        public void AwaitStartStopSignal_exit() {
            AwaitStartStopSignalExit();
        }
        
        //## statechart_method 
        public int terminationstate_4_takeEvent(short id) {
            int res = RiJStateReactive.TAKE_EVENT_NOT_CONSUMED;
            res = state_6_takeEvent(id);
            return res;
        }
        
        //## statechart_method 
        public void state_6EntDef() {
            Await_entDef();
        }
        
        //## statechart_method 
        public void SetEnvExit() {
            itsRiJThread.unschedTimeout(AC_Timeout_SetEnv_id, this);
        }
        
        //## statechart_method 
        public void AwaitEnter() {
            itsRiJThread.schedTimeout(200, AC_Timeout_Await_id, this, null);
        }
        
        //## statechart_method 
        public int state_6_takeEvent(short id) {
            int res = RiJStateReactive.TAKE_EVENT_NOT_CONSUMED;
            return res;
        }
        
        //## statechart_method 
        public void WorkStart_exit() {
            state_5_exit();
            state_6_exit();
            WorkStartExit();
        }
        
        //## statechart_method 
        public void WorkStartExit() {
        }
        
        //## statechart_method 
        public void terminationstate_4Exit() {
        }
        
        //## statechart_method 
        public void sendaction_2_enter() {
            rootState_subState = sendaction_2;
            rootState_active = sendaction_2;
            sendaction_2Enter();
        }
        
        //## statechart_method 
        public int AwaitStartStopSignal_takeEvent(short id) {
            int res = RiJStateReactive.TAKE_EVENT_NOT_CONSUMED;
            if(event.isTypeOf(ACTrigger.ACTrigger_Default_id))
                {
                    res = AwaitStartStopSignalTakeACTrigger();
                }
            
            if(res == RiJStateReactive.TAKE_EVENT_NOT_CONSUMED)
                {
                    res = state_5_takeEvent(id);
                }
            return res;
        }
        
        //## statechart_method 
        public void SetEnv_enter() {
            state_5_subState = SetEnv;
            state_5_active = SetEnv;
            SetEnvEnter();
        }
        
        //## statechart_method 
        public void SetEnv_entDef() {
            SetEnv_enter();
        }
        
        //## statechart_method 
        public void Await_exit() {
            AwaitExit();
        }
        
        //## statechart_method 
        public int Work_takeEvent(short id) {
            int res = RiJStateReactive.TAKE_EVENT_NOT_CONSUMED;
            if(event.isTypeOf(RiJEvent.TIMEOUT_EVENT_ID))
                {
                    res = WorkTakeRiJTimeout();
                }
            
            if(res == RiJStateReactive.TAKE_EVENT_NOT_CONSUMED)
                {
                    res = state_6_takeEvent(id);
                }
            return res;
        }
        
        //## statechart_method 
        public int rootState_takeEvent(short id) {
            int res = RiJStateReactive.TAKE_EVENT_NOT_CONSUMED;
            return res;
        }
        
        //## statechart_method 
        public void terminationstate_4_enter() {
            state_6_subState = terminationstate_4;
            state_6_active = terminationstate_4;
            terminationstate_4Enter();
        }
        
        //## statechart_method 
        public void SetEnvEnter() {
            itsRiJThread.schedTimeout(200, AC_Timeout_SetEnv_id, this, null);
        }
        
        //## statechart_method 
        public int state_5_takeEvent(short id) {
            int res = RiJStateReactive.TAKE_EVENT_NOT_CONSUMED;
            return res;
        }
        
        //## statechart_method 
        public void rootState_enter() {
            rootStateEnter();
        }
        
        //## statechart_method 
        public void rootStateEnter() {
        }
        
        //## statechart_method 
        public int WorkTakeRiJTimeout() {
            int res = RiJStateReactive.TAKE_EVENT_NOT_CONSUMED;
            if(event.getTimeoutId() == AC_Timeout_Work_id)
                {
                    Work_exit();
                    Await_entDef();
                    res = RiJStateReactive.TAKE_EVENT_COMPLETE;
                }
            return res;
        }
        
        //## statechart_method 
        public void Work_enter() {
            state_6_subState = Work;
            state_6_active = Work;
            WorkEnter();
        }
        
        //## statechart_method 
        public void WorkEnter() {
            itsRiJThread.schedTimeout(200, AC_Timeout_Work_id, this, null);
        }
        
        //## statechart_method 
        public void WorkStart_enter() {
            rootState_subState = WorkStart;
            rootState_active = WorkStart;
            WorkStartEnter();
        }
        
        //## statechart_method 
        public int SetEnvTakeRiJTimeout() {
            int res = RiJStateReactive.TAKE_EVENT_NOT_CONSUMED;
            if(event.getTimeoutId() == AC_Timeout_SetEnv_id)
                {
                    SetEnv_exit();
                    AwaitStartStopSignal_entDef();
                    res = RiJStateReactive.TAKE_EVENT_COMPLETE;
                }
            return res;
        }
        
        //## statechart_method 
        public int AwaitTakeRiJTimeout() {
            int res = RiJStateReactive.TAKE_EVENT_NOT_CONSUMED;
            if(event.getTimeoutId() == AC_Timeout_Await_id)
                {
                    //## transition 4 
                    if(isBroken)
                        {
                            Await_exit();
                            //#[ transition 4 
                            parent.gen(new ACBroken());
                            //#]
                            terminationstate_4_entDef();
                            res = RiJStateReactive.TAKE_EVENT_COMPLETE;
                        }
                    else
                        {
                            //## transition 5 
                            if(!isBroken)
                                {
                                    //## transition 6 
                                    if(shouldWork)
                                        {
                                            Await_exit();
                                            Work_entDef();
                                            res = RiJStateReactive.TAKE_EVENT_COMPLETE;
                                        }
                                    else
                                        {
                                            //## transition 7 
                                            if(!shouldWork)
                                                {
                                                    Await_exit();
                                                    Await_entDef();
                                                    res = RiJStateReactive.TAKE_EVENT_COMPLETE;
                                                }
                                        }
                                }
                        }
                }
            return res;
        }
        
        //## statechart_method 
        public void AwaitExit() {
            itsRiJThread.unschedTimeout(AC_Timeout_Await_id, this);
        }
        
        //## statechart_method 
        public void terminationstate_4_entDef() {
            terminationstate_4_enter();
        }
        
        //## statechart_method 
        public void AwaitStartStopSignal_enter() {
            state_5_subState = AwaitStartStopSignal;
            state_5_active = AwaitStartStopSignal;
            AwaitStartStopSignalEnter();
        }
        
        //## statechart_method 
        public void AwaitStartStopSignal_entDef() {
            AwaitStartStopSignal_enter();
        }
        
        //## statechart_method 
        public void SetEnv_exit() {
            SetEnvExit();
        }
        
        //## statechart_method 
        public int Await_takeEvent(short id) {
            int res = RiJStateReactive.TAKE_EVENT_NOT_CONSUMED;
            if(event.isTypeOf(RiJEvent.TIMEOUT_EVENT_ID))
                {
                    res = AwaitTakeRiJTimeout();
                }
            
            if(res == RiJStateReactive.TAKE_EVENT_NOT_CONSUMED)
                {
                    res = state_6_takeEvent(id);
                }
            return res;
        }
        
        //## statechart_method 
        public void rootStateEntDef() {
            sendaction_2_entDef();
        }
        
        //## statechart_method 
        public int AwaitStartStopSignalTakeACTrigger() {
            ACTrigger params = (ACTrigger) event;
            int res = RiJStateReactive.TAKE_EVENT_NOT_CONSUMED;
            AwaitStartStopSignal_exit();
            //#[ transition 2 
            shouldWork = params.isOn;
            //#]
            SetEnv_entDef();
            res = RiJStateReactive.TAKE_EVENT_COMPLETE;
            return res;
        }
        
        //## statechart_method 
        public void state_5Exit() {
        }
        
        //## statechart_method 
        public void state_5_entDef() {
            state_5_enter();
            state_5EntDef();
        }
        
        //## statechart_method 
        public void Work_exit() {
            WorkExit();
        }
        
        //## statechart_method 
        public void state_6Enter() {
        }
        
        //## statechart_method 
        public int sendaction_2TakeACSYNACK() {
            int res = RiJStateReactive.TAKE_EVENT_NOT_CONSUMED;
            sendaction_2_exit();
            WorkStart_entDef();
            res = RiJStateReactive.TAKE_EVENT_COMPLETE;
            return res;
        }
        
        //## statechart_method 
        public void state_5Enter() {
        }
        
        //## statechart_method 
        public void terminationstate_4Enter() {
        }
        
        //## statechart_method 
        public void state_6Exit() {
        }
        
        //## statechart_method 
        public void Await_enter() {
            state_6_subState = Await;
            state_6_active = Await;
            AwaitEnter();
        }
        
        //## statechart_method 
        public void rootStateExit() {
        }
        
        //## statechart_method 
        public void sendaction_2Enter() {
            //#[ state sendaction_2.(Entry) 
            parent.gen(new Default.ACSYN());
            //#]
        }
        
        //## statechart_method 
        public void sendaction_2_entDef() {
            sendaction_2_enter();
        }
        
        //## statechart_method 
        public int SetEnv_takeEvent(short id) {
            int res = RiJStateReactive.TAKE_EVENT_NOT_CONSUMED;
            if(event.isTypeOf(RiJEvent.TIMEOUT_EVENT_ID))
                {
                    res = SetEnvTakeRiJTimeout();
                }
            
            if(res == RiJStateReactive.TAKE_EVENT_NOT_CONSUMED)
                {
                    res = state_5_takeEvent(id);
                }
            return res;
        }
        
        //## statechart_method 
        public void state_5_enter() {
            state_5Enter();
        }
        
        //## statechart_method 
        public void WorkExit() {
            itsRiJThread.unschedTimeout(AC_Timeout_Work_id, this);
        }
        
        //## statechart_method 
        public void state_6_exit() {
            switch (state_6_subState) {
                case Work:
                {
                    Work_exit();
                }
                break;
                case terminationstate_4:
                {
                    terminationstate_4_exit();
                }
                break;
                case Await:
                {
                    Await_exit();
                }
                break;
                default:
                    break;
            }
            state_6_subState = RiJNonState;
            state_6Exit();
        }
        
        //## statechart_method 
        public void AwaitStartStopSignalEnter() {
        }
        
        //## statechart_method 
        public void state_5_exit() {
            switch (state_5_subState) {
                case AwaitStartStopSignal:
                {
                    AwaitStartStopSignal_exit();
                }
                break;
                case SetEnv:
                {
                    SetEnv_exit();
                }
                break;
                default:
                    break;
            }
            state_5_subState = RiJNonState;
            state_5Exit();
        }
        
        //## statechart_method 
        public void Await_entDef() {
            Await_enter();
        }
        
        //## statechart_method 
        public void terminationstate_4_exit() {
            terminationstate_4Exit();
        }
        
        //## statechart_method 
        public void state_6_enter() {
            state_6Enter();
        }
        
        //## statechart_method 
        public int WorkStart_takeEvent(short id) {
            int res = RiJStateReactive.TAKE_EVENT_NOT_CONSUMED;
            return res;
        }
        
    }
}
/*********************************************************************
	File Path	: DefaultComponent/DefaultConfig/Default/AC.java
*********************************************************************/

